package com.example.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Data;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.ArrayList;

@Data
@Component
@ConfigurationProperties(prefix = "mqtt")
public class MqttServerConfig {
    private int port;
    private int bossThreads;
    private int workerThreads;
    private Network network = new Network();
    private int sessionExpiry;
    private int maxMessageSize;
    private MqttPersistenceConfig persistence;

    @Data
    public static class Network {
        private NetworkConfig lan = new NetworkConfig();
        private WanConfig wan = new WanConfig();
    }

    @Data
    public static class NetworkConfig {
        private boolean enabled;
        private String host;
        private Protocol mqtt = new Protocol();
        private WebSocket ws = new WebSocket();
    }

    @Data
    public static class Protocol {
        private boolean enabled;
        private int port;
    }

    @Data
    public static class WebSocket extends Protocol {
        private String path;
    }

    @Data
    public static class WanConfig extends NetworkConfig {
        private SSL ssl = new SSL();
    }

    @Data
    public static class SSL {
        private boolean enabled;
        private String keyStore;
        private String keyStorePassword;
        private String keyPassword;
    }

    @Data
    public static class Auth {
        private boolean enabled = true;
        private List<User> users = new ArrayList<>();
    }

    @Data
    public static class User {
        private String username;
        private String password;
        private List<String> permissions = new ArrayList<>();
    }
} 